<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTrainingReviewsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('training_reviews', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('session_id');
            $table->unsignedTinyInteger('overall_score')->nullable();
            $table->text('best_messages')->nullable()->comment('最佳话术消息ID数组(JSON字符串)');
            $table->text('error_messages')->nullable()->comment('错误话术消息ID数组(JSON字符串)');
            $table->text('suggestions')->nullable()->comment('改进建议(JSON字符串)');
            $table->text('ability_changes')->nullable()->comment('能力变化数据(JSON字符串)');
            $table->timestamp('created_at')->useCurrent();
            
            // 外键约束
            $table->foreign('session_id')->references('id')->on('training_sessions')->onDelete('cascade');
            
            // 索引
            $table->index(['session_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('training_reviews');
    }
}